<?php

namespace App\Http\Requests\AuthRequests;

use Illuminate\Foundation\Http\FormRequest;

class LoginRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'username' => ['required'],
            'password' => ['required', 'min:6', 'max:18']
        ];
        if (is_numeric($this->input('username'))) { // 手机号登录
//            $rules['code'] = [
//                'required',
//                'smsCode:+86' . $this->input('username')
//            ];
        } else { // 邮箱登录
//            $rules['code'] = [
//                'required',
//                'emailCode:' . $this->input('username')
//            ];
        }

        return $rules;
    }


    public function messages()
    {
        return [
            'username.required' => __('请填写账号'),
            'password.required' => __('登录密码必填'),
            'password.min'      => __('登录密码至少6位数'),
            'password.max'      => __('登录密码至多18位'),
            'code.required'      => __('验证码必填'),
        ];
    }
}
